import http from '@/utils/http/axios';

export interface BasicResponseModel<T = any> {
  code: string;
  msg: string;
  data: T;
}

export interface BasicPageParams {
  pageNumber: number;
  pageSize: number;
  total: number;
}

/**
 * @description: 获取用户信息
 */
export function getUserInfo() {
  return http.request({
    url: '/admin_info',
    method: 'get',
  });
}

/**
 * @description: 用户登录
 */
export function login(params) {
  return http.request<BasicResponseModel>(
    {
      url: '/system/sysLogin/login',
      method: 'post',
      params,
    },
    {
      isTransformResponse: false,
    }
  );
}

/**
 * @description: 用户修改密码
 */
export function changePassword(params, uid) {
  return http.request(
    {
      url: `/user/u${uid}/changepw`,
      method: 'POST',
      params,
    },
    {
      isTransformResponse: false,
    }
  );
}

/**
 * @description: 用户登出
 */
export function logout(params) {
  return http.request({
    url: '/login/logout',
    method: 'POST',
    params,
  });
}

// 添加用户
export function addUserApi(params = {}) {
  return http.request({
    url: '/system/sysUser',
    method: 'POST',
    params,
  });
}

// 修改用户
export function modifyUserApi(params = {}) {
  return http.request({
    url: '/system/sysUser',
    method: 'PUT',
    params,
  });
}

// 查询用户
export function getUserListApi(params = {}) {
  return http.request({
    url: '/system/sysUser/page',
    method: 'GET',
    params,
  });
}

// 删除用户
export function deleteUserApi(params) {
  return http.request({
    url: `/system/sysUser/${params.id}`,
    method: 'DELETE',
  });
}

// 重置用户密码
export function resetUserPasswordApi(params) {
  return http.request({
    url: `/system/sysUser/reset/${params.id}`,
    method: 'PUT',
  });
}

// 批量删除
export function deleteUsersApi(params) {
  return http.request({
    url: `/system/sysUser/delete`,
    method: 'DELETE',
    data: params,
  });
}

// 导出数据的接口
export function exportUserApi(params = {}) {
  return http.request({
    url: `/system/sysUser/export`,
    method: 'POST',
    data: params,
    responseType: 'blob',
  });
}

// 保存个人信息
export function setUserInfo(params) {
  return http.request({
    url: `/system/sysUser`,
    method: 'PUT',
    params,
  });
}

// 保存个人信息
export function getUserInfoByNameApi(params) {
  return http.request({
    url: `/system/sysUser/getByUserName`,
    method: 'PUT',
    params,
  });
}
